package com.example.autopia.utilities

import android.os.CountDownTimer

class TimerCollection {
    private var countDownTimer: CountDownTimer? = null

    interface TimerListener {
        fun onTimerTick(millisUntilFinished: Long)
        fun onTimerFinish()
    }

    fun startTimer(startTime: Long, endTime: Long, listener: TimerListener) {
        val duration = endTime - startTime

        countDownTimer = object : CountDownTimer(duration*1000, 1000) {
            override fun onTick(millisUntilFinished: Long) {
                listener.onTimerTick(millisUntilFinished)
            }

            override fun onFinish() {
                listener.onTimerFinish()
            }
        }

        countDownTimer?.start()
    }

    fun cancelTimer() {
        countDownTimer?.cancel()
    }
}